YaoShuiState =class("YaoShuiState",function () return StateBase.new()  end)
local YAOSHUI_EFFECT_SIZE =5 --持续管子个数

function YaoShuiState:ctor()
  self.isEnter =false
end


function YaoShuiState:onTiming()
 local interval =Context.interval
 local scene =display.getRunningScene()
 if  self.isEnter  and self.currentScore and scene.uiLayer.currentScore >=self.currentScore+YAOSHUI_EFFECT_SIZE then
    self:onExit()
    return
 end
  viewController:tick(interval)
  scene.updateTime =scene.updateTime+interval
  scene._time=scene._time+interval
  if scene._time>1 then
   scene.AnimationLayer:onUpdate()
   scene.uiLayer:onUpdate()
   scene._time =0
  end
 scene.uiLayer:animationUpdate()
 if scene.updateTime>0.1 then
   scene:isColliWithFish() --checkColliWith 
   local fishRect =scene.uiLayer:getFishRect()
   scene.AnimationLayer.layouts:colliCheckWithCoin(fishRect)
   if scene:passOne() then
    scene.uiLayer:changeScore()
    print("pass one")
   end
   scene.updateTime =0
 end
end



function YaoShuiState:onColliWithUp(ui)
   if ui.pillarUp then
     local scene =display.getRunningScene()
      scene:vabration()
     StateBase.playXiaoShiUp(self,ui)
     ui.pillarUp:fadeOut(1)
     ui.pillarUp =nil
   end
end
function YaoShuiState:onColliWithDown(ui)
  if ui.pillarDown then
    local scene =display.getRunningScene()
    scene:vabration()
    StateBase.playXiaoShiDown(self,ui)
    ui.pillarDown:fadeOut(1)
    ui.pillarDown =nil
  end
end


function YaoShuiState:onEnter()
   self.isEnter =true
  local scene =display.getRunningScene()
  local fish =scene.uiLayer.fish
  fish.fish:setScale(1.5)
  local fx,fy =fish.fish:getPosition()
  fish:playShanXian(fx,fy)
  fish.shanxian:setScale(1.5) 
   local layer =scene.AnimationLayer
   local px,py =layer:getPosition()
   local fx,fy =scene.uiLayer.fish:getPosition()
   local point =CCNode.convertToWorldSpace(scene.uiLayer.fish,CCPoint(fx,fy))
   layer.layouts:resizeTo(point.x,layer,YAOSHUI_EFFECT_SIZE)
   self.currentScore =scene.uiLayer.currentScore
end

function YaoShuiState:onExit()
  self.isEnter =false
  local scene =display.getRunningScene()
  local fish =scene.uiLayer.fish
  fish.fish:setScale(1)
  local fx,fy =fish.fish:getPosition()
  fish:playShanXian(fx,fy)
  local px,py =scene.AnimationLayer:getPosition()
  scene.AnimationLayer.layouts:resumeCreateUI(scene.AnimationLayer,px)
  viewController:setStateRunning()

end

